package com.kyleswebspace.propertyanalyzer.gui;

import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.FocusEvent;
import java.awt.event.ItemEvent;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;

import com.kyleswebspace.parser.FieldParser;
import com.kyleswebspace.propertyanalyzer.config.ArcaFont;
import com.kyleswebspace.propertyanalyzer.config.ColorBox;
import com.kyleswebspace.propertyanalyzer.model.DataModel;

public class ApproxTablesFrame extends JFrame implements Updateable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 120449220246983370L;
	
	private DataModel dm;
	
	private JPanel appraisalPanel, legalPanel, inspectionPanel, outterPanel;
	private JTextField 	appraisalUnitsFieldAA, appraisalUnitsFieldAB,
						appraisalUnitsFieldBA, appraisalUnitsFieldBB,
						appraisalUnitsFieldCA, appraisalUnitsFieldCB,
						appraisalUnitsFieldDA, appraisalUnitsFieldDB;
	private JTextField 	legalUnitsFieldAA, legalUnitsFieldAB,
						legalUnitsFieldBA, legalUnitsFieldBB,
						legalUnitsFieldCA, legalUnitsFieldCB,
						legalUnitsFieldDA, legalUnitsFieldDB;
	private JTextField 	inspectionUnitsFieldAA, inspectionUnitsFieldAB,
						inspectionUnitsFieldBA, inspectionUnitsFieldBB,
						inspectionUnitsFieldCA, inspectionUnitsFieldCB,
						inspectionUnitsFieldDA, inspectionUnitsFieldDB;
	private JTextField appraisalFeeFieldA, appraisalFeeFieldB, appraisalFeeFieldC, appraisalFeeFieldD;
	private JTextField legalFeeFieldA, legalFeeFieldB, legalFeeFieldC, legalFeeFieldD;
	private JTextField inspectionFeeFieldA, inspectionFeeFieldB, inspectionFeeFieldC, inspectionFeeFieldD;
	private JLabel appraisalToLabelA, appraisalToLabelB, appraisalToLabelC, appraisalToLabelD;
	private JLabel legalToLabelA, legalToLabelB, legalToLabelC, legalToLabelD;
	private JLabel inspectionToLabelA, inspectionToLabelB, inspectionToLabelC, inspectionToLabelD;
	private JLabel appraisalUnitsEqualLabelA, appraisalUnitsEqualLabelB, appraisalUnitsEqualLabelC, appraisalUnitsEqualLabelD;
	private JLabel legalUnitsEqualLabelA, legalUnitsEqualLabelB, legalUnitsEqualLabelC, legalUnitsEqualLabelD;
	private JLabel inspectionUnitsEqualLabelA, inspectionUnitsEqualLabelB, inspectionUnitsEqualLabelC, inspectionUnitsEqualLabelD;
	
	private final Font appFont = ArcaFont.appFont;
	private final Color innerPanelColor = ColorBox.innerPanelColor;
	private final Color backgroundPanelColor = ColorBox.backgroundPanelColor;
	
	public ApproxTablesFrame(DataModel dm) {
		this.dm = dm;
		dm.register(this);
		
		outterPanel = new JPanel();
		outterPanel.setBackground(backgroundPanelColor);
		appraisalPanel = new JPanel();
		appraisalPanel.setBackground(innerPanelColor);
		legalPanel = new JPanel();
		legalPanel.setBackground(innerPanelColor);
		inspectionPanel = new JPanel();
		inspectionPanel.setBackground(innerPanelColor);
		outterPanel.setLayout(new GridBagLayout());
		appraisalPanel.setLayout(new GridBagLayout());
		legalPanel.setLayout(new GridBagLayout());
		inspectionPanel.setLayout(new GridBagLayout());
		GridBagConstraints constraints = new GridBagConstraints();
		TitledBorder title;
		constraints.ipadx = 20;
		
		appraisalUnitsFieldAA = new JTextField(2);
		appraisalUnitsFieldAA.addFocusListener(this);
		appraisalUnitsFieldAA.setFocusable(false);
		appraisalUnitsFieldAA.setFont(appFont);
		appraisalUnitsFieldAA.setHorizontalAlignment(JTextField.RIGHT);
		appraisalUnitsFieldAB = new JTextField(2);
		appraisalUnitsFieldAB.addFocusListener(this);
		appraisalUnitsFieldAB.setFocusable(false);
		appraisalUnitsFieldAB.setFont(appFont);
		appraisalUnitsFieldAB.setHorizontalAlignment(JTextField.RIGHT);
		appraisalUnitsFieldBA = new JTextField(2);
		appraisalUnitsFieldBA.addFocusListener(this);
		appraisalUnitsFieldBA.setFocusable(false);
		appraisalUnitsFieldBA.setFont(appFont);
		appraisalUnitsFieldBA.setHorizontalAlignment(JTextField.RIGHT);
		appraisalUnitsFieldBB = new JTextField(2);
		appraisalUnitsFieldBB.addFocusListener(this);
		appraisalUnitsFieldBB.setFocusable(false);
		appraisalUnitsFieldBB.setFont(appFont);
		appraisalUnitsFieldBB.setHorizontalAlignment(JTextField.RIGHT);
		appraisalUnitsFieldCA = new JTextField(2);
		appraisalUnitsFieldCA.addFocusListener(this);
		appraisalUnitsFieldCA.setFocusable(false);
		appraisalUnitsFieldCA.setFont(appFont);
		appraisalUnitsFieldCA.setHorizontalAlignment(JTextField.RIGHT);
		appraisalUnitsFieldCB = new JTextField(2);
		appraisalUnitsFieldCB.addFocusListener(this);
		appraisalUnitsFieldCB.setFocusable(false);
		appraisalUnitsFieldCB.setFont(appFont);
		appraisalUnitsFieldCB.setHorizontalAlignment(JTextField.RIGHT);
		appraisalUnitsFieldDA = new JTextField(2);
		appraisalUnitsFieldDA.addFocusListener(this);
		appraisalUnitsFieldDA.setFocusable(false);
		appraisalUnitsFieldDA.setFont(appFont);
		appraisalUnitsFieldDA.setHorizontalAlignment(JTextField.RIGHT);
		appraisalUnitsFieldDB = new JTextField(2);
		appraisalUnitsFieldDB.addFocusListener(this);
		appraisalUnitsFieldDB.setFocusable(false);
		appraisalUnitsFieldDB.setFont(appFont);
		appraisalUnitsFieldDB.setHorizontalAlignment(JTextField.RIGHT);
		
		legalUnitsFieldAA = new JTextField(2);
		legalUnitsFieldAA.addFocusListener(this);
		legalUnitsFieldAA.setFocusable(false);
		legalUnitsFieldAA.setFont(appFont);
		legalUnitsFieldAA.setHorizontalAlignment(JTextField.RIGHT);
		legalUnitsFieldAB = new JTextField(2);
		legalUnitsFieldAB.addFocusListener(this);
		legalUnitsFieldAB.setFocusable(false);
		legalUnitsFieldAB.setFont(appFont);
		legalUnitsFieldAB.setHorizontalAlignment(JTextField.RIGHT);
		legalUnitsFieldBA = new JTextField(2);
		legalUnitsFieldBA.addFocusListener(this);
		legalUnitsFieldBA.setFocusable(false);
		legalUnitsFieldBA.setFont(appFont);
		legalUnitsFieldBA.setHorizontalAlignment(JTextField.RIGHT);
		legalUnitsFieldBB = new JTextField(2);
		legalUnitsFieldBB.addFocusListener(this);
		legalUnitsFieldBB.setFocusable(false);
		legalUnitsFieldBB.setFont(appFont);
		legalUnitsFieldBB.setHorizontalAlignment(JTextField.RIGHT);
		legalUnitsFieldCA = new JTextField(2);
		legalUnitsFieldCA.addFocusListener(this);
		legalUnitsFieldCA.setFocusable(false);
		legalUnitsFieldCA.setFont(appFont);
		legalUnitsFieldCA.setHorizontalAlignment(JTextField.RIGHT);
		legalUnitsFieldCB = new JTextField(2);
		legalUnitsFieldCB.addFocusListener(this);
		legalUnitsFieldCB.setFocusable(false);
		legalUnitsFieldCB.setFont(appFont);
		legalUnitsFieldCB.setHorizontalAlignment(JTextField.RIGHT);
		legalUnitsFieldDA = new JTextField(2);
		legalUnitsFieldDA.addFocusListener(this);
		legalUnitsFieldDA.setFocusable(false);
		legalUnitsFieldDA.setFont(appFont);
		legalUnitsFieldDA.setHorizontalAlignment(JTextField.RIGHT);
		legalUnitsFieldDB = new JTextField(2);
		legalUnitsFieldDB.addFocusListener(this);
		legalUnitsFieldDB.setFocusable(false);
		legalUnitsFieldDB.setFont(appFont);
		legalUnitsFieldDB.setHorizontalAlignment(JTextField.RIGHT);
		
		inspectionUnitsFieldAA = new JTextField(2);
		inspectionUnitsFieldAA.addFocusListener(this);
		inspectionUnitsFieldAA.setFocusable(false);
		inspectionUnitsFieldAA.setFont(appFont);
		inspectionUnitsFieldAA.setHorizontalAlignment(JTextField.RIGHT);
		inspectionUnitsFieldAB = new JTextField(2);
		inspectionUnitsFieldAB.addFocusListener(this);
		inspectionUnitsFieldAB.setFocusable(false);
		inspectionUnitsFieldAB.setFont(appFont);
		inspectionUnitsFieldAB.setHorizontalAlignment(JTextField.RIGHT);
		inspectionUnitsFieldBA = new JTextField(2);
		inspectionUnitsFieldBA.addFocusListener(this);
		inspectionUnitsFieldBA.setFocusable(false);
		inspectionUnitsFieldBA.setFont(appFont);
		inspectionUnitsFieldBA.setHorizontalAlignment(JTextField.RIGHT);
		inspectionUnitsFieldBB = new JTextField(2);
		inspectionUnitsFieldBB.addFocusListener(this);
		inspectionUnitsFieldBB.setFocusable(false);
		inspectionUnitsFieldBB.setFont(appFont);
		inspectionUnitsFieldBB.setHorizontalAlignment(JTextField.RIGHT);
		inspectionUnitsFieldCA = new JTextField(2);
		inspectionUnitsFieldCA.addFocusListener(this);
		inspectionUnitsFieldCA.setFocusable(false);
		inspectionUnitsFieldCA.setFont(appFont);
		inspectionUnitsFieldCA.setHorizontalAlignment(JTextField.RIGHT);
		inspectionUnitsFieldCB = new JTextField(2);
		inspectionUnitsFieldCB.addFocusListener(this);
		inspectionUnitsFieldCB.setFocusable(false);
		inspectionUnitsFieldCB.setFont(appFont);
		inspectionUnitsFieldCB.setHorizontalAlignment(JTextField.RIGHT);
		inspectionUnitsFieldDA = new JTextField(2);
		inspectionUnitsFieldDA.addFocusListener(this);
		inspectionUnitsFieldDA.setFocusable(false);
		inspectionUnitsFieldDA.setFont(appFont);
		inspectionUnitsFieldDA.setHorizontalAlignment(JTextField.RIGHT);
		inspectionUnitsFieldDB = new JTextField(2);
		inspectionUnitsFieldDB.addFocusListener(this);
		inspectionUnitsFieldDB.setFocusable(false);
		inspectionUnitsFieldDB.setFont(appFont);
		inspectionUnitsFieldDB.setHorizontalAlignment(JTextField.RIGHT);
		
		appraisalFeeFieldA = new JTextField(2);
		appraisalFeeFieldA.addFocusListener(this);
		appraisalFeeFieldA.setFocusable(false);
		appraisalFeeFieldA.setFont(appFont);
		appraisalFeeFieldA.setHorizontalAlignment(JTextField.RIGHT);
		appraisalFeeFieldB = new JTextField(2);
		appraisalFeeFieldB.addFocusListener(this);
		appraisalFeeFieldB.setFocusable(false);
		appraisalFeeFieldB.setFont(appFont);
		appraisalFeeFieldB.setHorizontalAlignment(JTextField.RIGHT);
		appraisalFeeFieldC = new JTextField(2);
		appraisalFeeFieldC.addFocusListener(this);
		appraisalFeeFieldC.setFocusable(false);
		appraisalFeeFieldC.setFont(appFont);
		appraisalFeeFieldC.setHorizontalAlignment(JTextField.RIGHT);
		appraisalFeeFieldD = new JTextField(2);
		appraisalFeeFieldD.addFocusListener(this);
		appraisalFeeFieldD.setFocusable(false);
		appraisalFeeFieldD.setFont(appFont);
		appraisalFeeFieldD.setHorizontalAlignment(JTextField.RIGHT);
		
		legalFeeFieldA = new JTextField(2);
		legalFeeFieldA.addFocusListener(this);
		legalFeeFieldA.setFocusable(false);
		legalFeeFieldA.setFont(appFont);
		legalFeeFieldA.setHorizontalAlignment(JTextField.RIGHT);
		legalFeeFieldB = new JTextField(2);
		legalFeeFieldB.addFocusListener(this);
		legalFeeFieldB.setFocusable(false);
		legalFeeFieldB.setFont(appFont);
		legalFeeFieldB.setHorizontalAlignment(JTextField.RIGHT);
		legalFeeFieldC = new JTextField(2);
		legalFeeFieldC.addFocusListener(this);
		legalFeeFieldC.setFocusable(false);
		legalFeeFieldC.setFont(appFont);
		legalFeeFieldC.setHorizontalAlignment(JTextField.RIGHT);
		legalFeeFieldD = new JTextField(2);
		legalFeeFieldD.addFocusListener(this);
		legalFeeFieldD.setFocusable(false);
		legalFeeFieldD.setFont(appFont);
		legalFeeFieldD.setHorizontalAlignment(JTextField.RIGHT);
		
		inspectionFeeFieldA = new JTextField(2);
		inspectionFeeFieldA.addFocusListener(this);
		inspectionFeeFieldA.setFocusable(false);
		inspectionFeeFieldA.setFont(appFont);
		inspectionFeeFieldA.setHorizontalAlignment(JTextField.RIGHT);
		inspectionFeeFieldB = new JTextField(2);
		inspectionFeeFieldB.addFocusListener(this);
		inspectionFeeFieldB.setFocusable(false);
		inspectionFeeFieldB.setFont(appFont);
		inspectionFeeFieldB.setHorizontalAlignment(JTextField.RIGHT);
		inspectionFeeFieldC = new JTextField(2);
		inspectionFeeFieldC.addFocusListener(this);
		inspectionFeeFieldC.setFocusable(false);
		inspectionFeeFieldC.setFont(appFont);
		inspectionFeeFieldC.setHorizontalAlignment(JTextField.RIGHT);
		inspectionFeeFieldD = new JTextField(2);
		inspectionFeeFieldD.addFocusListener(this);
		inspectionFeeFieldD.setFocusable(false);
		inspectionFeeFieldD.setFont(appFont);
		inspectionFeeFieldD.setHorizontalAlignment(JTextField.RIGHT);
		
		appraisalToLabelA = new JLabel("to");
		appraisalToLabelA.setFont(appFont);
		appraisalToLabelA.setHorizontalAlignment(JLabel.CENTER);
		appraisalToLabelB = new JLabel("to");
		appraisalToLabelB.setFont(appFont);
		appraisalToLabelB.setHorizontalAlignment(JLabel.CENTER);
		appraisalToLabelC = new JLabel("to");
		appraisalToLabelC.setFont(appFont);
		appraisalToLabelC.setHorizontalAlignment(JLabel.CENTER);
		appraisalToLabelD = new JLabel("to");
		appraisalToLabelD.setFont(appFont);
		appraisalToLabelD.setHorizontalAlignment(JLabel.CENTER);
		
		legalToLabelA = new JLabel("to");
		legalToLabelA.setFont(appFont);
		legalToLabelA.setHorizontalAlignment(JLabel.CENTER);
		legalToLabelB = new JLabel("to");
		legalToLabelB.setFont(appFont);
		legalToLabelB.setHorizontalAlignment(JLabel.CENTER);
		legalToLabelC = new JLabel("to");
		legalToLabelC.setFont(appFont);
		legalToLabelC.setHorizontalAlignment(JLabel.CENTER);
		legalToLabelD = new JLabel("to");
		legalToLabelD.setFont(appFont);
		legalToLabelD.setHorizontalAlignment(JLabel.CENTER);
		
		inspectionToLabelA = new JLabel("to");
		inspectionToLabelA.setFont(appFont);
		inspectionToLabelA.setHorizontalAlignment(JLabel.CENTER);
		inspectionToLabelB = new JLabel("to");
		inspectionToLabelB.setFont(appFont);
		inspectionToLabelB.setHorizontalAlignment(JLabel.CENTER);
		inspectionToLabelC = new JLabel("to");
		inspectionToLabelC.setFont(appFont);
		inspectionToLabelC.setHorizontalAlignment(JLabel.CENTER);
		inspectionToLabelD = new JLabel("to");
		inspectionToLabelD.setFont(appFont);
		inspectionToLabelD.setHorizontalAlignment(JLabel.CENTER);
		
		appraisalUnitsEqualLabelA = new JLabel("units  =");
		appraisalUnitsEqualLabelA.setHorizontalAlignment(JLabel.CENTER);
		appraisalUnitsEqualLabelA.setFont(appFont);
		appraisalUnitsEqualLabelB = new JLabel("units  =");
		appraisalUnitsEqualLabelB.setHorizontalAlignment(JLabel.CENTER);
		appraisalUnitsEqualLabelB.setFont(appFont);
		appraisalUnitsEqualLabelC = new JLabel("units  =");
		appraisalUnitsEqualLabelC.setHorizontalAlignment(JLabel.CENTER);
		appraisalUnitsEqualLabelC.setFont(appFont);
		appraisalUnitsEqualLabelD = new JLabel("units  =");
		appraisalUnitsEqualLabelD.setHorizontalAlignment(JLabel.CENTER);
		appraisalUnitsEqualLabelD.setFont(appFont);
		
		legalUnitsEqualLabelA = new JLabel("units  =");
		legalUnitsEqualLabelA.setHorizontalAlignment(JLabel.CENTER);
		legalUnitsEqualLabelA.setFont(appFont);
		legalUnitsEqualLabelB = new JLabel("units  =");
		legalUnitsEqualLabelB.setHorizontalAlignment(JLabel.CENTER);
		legalUnitsEqualLabelB.setFont(appFont);
		legalUnitsEqualLabelC = new JLabel("units  =");
		legalUnitsEqualLabelC.setHorizontalAlignment(JLabel.CENTER);
		legalUnitsEqualLabelC.setFont(appFont);
		legalUnitsEqualLabelD = new JLabel("units  =");
		legalUnitsEqualLabelD.setHorizontalAlignment(JLabel.CENTER);
		legalUnitsEqualLabelD.setFont(appFont);
		
		inspectionUnitsEqualLabelA = new JLabel("units  =");
		inspectionUnitsEqualLabelA.setHorizontalAlignment(JLabel.CENTER);
		inspectionUnitsEqualLabelA.setFont(appFont);
		inspectionUnitsEqualLabelB = new JLabel("units  =");
		inspectionUnitsEqualLabelB.setHorizontalAlignment(JLabel.CENTER);
		inspectionUnitsEqualLabelB.setFont(appFont);
		inspectionUnitsEqualLabelC = new JLabel("units  =");
		inspectionUnitsEqualLabelC.setHorizontalAlignment(JLabel.CENTER);
		inspectionUnitsEqualLabelC.setFont(appFont);
		inspectionUnitsEqualLabelD = new JLabel("units  =");
		inspectionUnitsEqualLabelD.setHorizontalAlignment(JLabel.CENTER);
		inspectionUnitsEqualLabelD.setFont(appFont);
		
		appraisalPanel.add(appraisalUnitsFieldAA,constraints);
		constraints.gridx = 1;
		appraisalPanel.add(appraisalToLabelA, constraints);
		constraints.gridx = 2;
		appraisalPanel.add(appraisalUnitsFieldAB, constraints);
		constraints.gridx = 3;
		appraisalPanel.add(appraisalUnitsEqualLabelA, constraints);
		constraints.gridx = 4;
		appraisalPanel.add(appraisalFeeFieldA, constraints);
		constraints.gridy = 1;
		constraints.gridx = 0;
		appraisalPanel.add(appraisalUnitsFieldBA,constraints);
		constraints.gridx = 1;
		appraisalPanel.add(appraisalToLabelB, constraints);
		constraints.gridx = 2;
		appraisalPanel.add(appraisalUnitsFieldBB, constraints);
		constraints.gridx = 3;
		appraisalPanel.add(appraisalUnitsEqualLabelB, constraints);
		constraints.gridx = 4;
		appraisalPanel.add(appraisalFeeFieldB, constraints);
		constraints.gridy = 2;
		constraints.gridx = 0;
		appraisalPanel.add(appraisalUnitsFieldCA,constraints);
		constraints.gridx = 1;
		appraisalPanel.add(appraisalToLabelC, constraints);
		constraints.gridx = 2;
		appraisalPanel.add(appraisalUnitsFieldCB, constraints);
		constraints.gridx = 3;
		appraisalPanel.add(appraisalUnitsEqualLabelC, constraints);
		constraints.gridx = 4;
		appraisalPanel.add(appraisalFeeFieldC, constraints);
		constraints.gridy = 3;
		constraints.gridx = 0;
		appraisalPanel.add(appraisalUnitsFieldDA,constraints);
		constraints.gridx = 1;
		appraisalPanel.add(appraisalToLabelD, constraints);
		constraints.gridx = 2;
		appraisalPanel.add(appraisalUnitsFieldDB, constraints);
		constraints.gridx = 3;
		appraisalPanel.add(appraisalUnitsEqualLabelD, constraints);
		constraints.gridx = 4;
		appraisalPanel.add(appraisalFeeFieldD, constraints);
		
		constraints = new GridBagConstraints();
		constraints.ipadx = 20;
		legalPanel.add(legalUnitsFieldAA,constraints);
		constraints.gridx = 1;
		legalPanel.add(legalToLabelA, constraints);
		constraints.gridx = 2;
		legalPanel.add(legalUnitsFieldAB, constraints);
		constraints.gridx = 3;
		legalPanel.add(legalUnitsEqualLabelA, constraints);
		constraints.gridx = 4;
		legalPanel.add(legalFeeFieldA, constraints);
		constraints.gridy = 1;
		constraints.gridx = 0;
		legalPanel.add(legalUnitsFieldBA,constraints);
		constraints.gridx = 1;
		legalPanel.add(legalToLabelB, constraints);
		constraints.gridx = 2;
		legalPanel.add(legalUnitsFieldBB, constraints);
		constraints.gridx = 3;
		legalPanel.add(legalUnitsEqualLabelB, constraints);
		constraints.gridx = 4;
		legalPanel.add(legalFeeFieldB, constraints);
		constraints.gridy = 2;
		constraints.gridx = 0;
		legalPanel.add(legalUnitsFieldCA,constraints);
		constraints.gridx = 1;
		legalPanel.add(legalToLabelC, constraints);
		constraints.gridx = 2;
		legalPanel.add(legalUnitsFieldCB, constraints);
		constraints.gridx = 3;
		legalPanel.add(legalUnitsEqualLabelC, constraints);
		constraints.gridx = 4;
		legalPanel.add(legalFeeFieldC, constraints);
		constraints.gridy = 3;
		constraints.gridx = 0;
		legalPanel.add(legalUnitsFieldDA,constraints);
		constraints.gridx = 1;
		legalPanel.add(legalToLabelD, constraints);
		constraints.gridx = 2;
		legalPanel.add(legalUnitsFieldDB, constraints);
		constraints.gridx = 3;
		legalPanel.add(legalUnitsEqualLabelD, constraints);
		constraints.gridx = 4;
		legalPanel.add(legalFeeFieldD, constraints);
		
		constraints = new GridBagConstraints();
		constraints.ipadx = 20;
		inspectionPanel.add(inspectionUnitsFieldAA,constraints);
		constraints.gridx = 1;
		inspectionPanel.add(inspectionToLabelA, constraints);
		constraints.gridx = 2;
		inspectionPanel.add(inspectionUnitsFieldAB, constraints);
		constraints.gridx = 3;
		inspectionPanel.add(inspectionUnitsEqualLabelA, constraints);
		constraints.gridx = 4;
		inspectionPanel.add(inspectionFeeFieldA, constraints);
		constraints.gridy = 1;
		constraints.gridx = 0;
		inspectionPanel.add(inspectionUnitsFieldBA,constraints);
		constraints.gridx = 1;
		inspectionPanel.add(inspectionToLabelB, constraints);
		constraints.gridx = 2;
		inspectionPanel.add(inspectionUnitsFieldBB, constraints);
		constraints.gridx = 3;
		inspectionPanel.add(inspectionUnitsEqualLabelB, constraints);
		constraints.gridx = 4;
		inspectionPanel.add(inspectionFeeFieldB, constraints);
		constraints.gridy = 2;
		constraints.gridx = 0;
		inspectionPanel.add(inspectionUnitsFieldCA,constraints);
		constraints.gridx = 1;
		inspectionPanel.add(inspectionToLabelC, constraints);
		constraints.gridx = 2;
		inspectionPanel.add(inspectionUnitsFieldCB, constraints);
		constraints.gridx = 3;
		inspectionPanel.add(inspectionUnitsEqualLabelC, constraints);
		constraints.gridx = 4;
		inspectionPanel.add(inspectionFeeFieldC, constraints);
		constraints.gridy = 3;
		constraints.gridx = 0;
		inspectionPanel.add(inspectionUnitsFieldDA,constraints);
		constraints.gridx = 1;
		inspectionPanel.add(inspectionToLabelD, constraints);
		constraints.gridx = 2;
		inspectionPanel.add(inspectionUnitsFieldDB, constraints);
		constraints.gridx = 3;
		inspectionPanel.add(inspectionUnitsEqualLabelD, constraints);
		constraints.gridx = 4;
		inspectionPanel.add(inspectionFeeFieldD, constraints);
		
		constraints = new GridBagConstraints();
		constraints.insets = new Insets(10,10,10,10);
		
		title = BorderFactory.createTitledBorder("Appraisal Fee Approx Table");
		appraisalPanel.setBorder(title);
		outterPanel.add(appraisalPanel, constraints);
		
		title = BorderFactory.createTitledBorder("Legal Fee Approx Table");
		legalPanel.setBorder(title);
		constraints.gridy = 1;
		outterPanel.add(legalPanel, constraints);
		
		title = BorderFactory.createTitledBorder("Inspection Fee Approx Table");
		inspectionPanel.setBorder(title);
		constraints.gridy = 2;
		outterPanel.add(inspectionPanel, constraints);
		
		constraints = new GridBagConstraints();
		this.add(outterPanel);
		this.pack();
		this.setTitle("Fee Approximation Tables");
		this.setLocationRelativeTo(null);
		
		updateFields();
	}
	
	public void updateFields() {
		this.appraisalUnitsFieldAA.setText(dm.getAppraisalFee1A());
		this.appraisalUnitsFieldAB.setText(dm.getAppraisalFee1B());
		this.appraisalFeeFieldA.setText(dm.getAppraisalFee1C());
		this.appraisalUnitsFieldBA.setText(dm.getAppraisalFee2A());
		this.appraisalUnitsFieldBB.setText(dm.getAppraisalFee2B());
		this.appraisalFeeFieldB.setText(dm.getAppraisalFee2C());
		this.appraisalUnitsFieldCA.setText(dm.getAppraisalFee3A());
		this.appraisalUnitsFieldCB.setText(dm.getAppraisalFee3B());
		this.appraisalFeeFieldC.setText(dm.getAppraisalFee3C());
		this.appraisalUnitsFieldDA.setText(dm.getAppraisalFee4A());
		this.appraisalUnitsFieldDB.setText(dm.getAppraisalFee4B());
		this.appraisalFeeFieldD.setText(dm.getAppraisalFee4C());
		
		this.legalUnitsFieldAA.setText(dm.getLegalFee1A());
		this.legalUnitsFieldAB.setText(dm.getLegalFee1B());
		this.legalFeeFieldA.setText(dm.getLegalFee1C());
		this.legalUnitsFieldBA.setText(dm.getLegalFee2A());
		this.legalUnitsFieldBB.setText(dm.getLegalFee2B());
		this.legalFeeFieldB.setText(dm.getLegalFee2C());
		this.legalUnitsFieldCA.setText(dm.getLegalFee3A());
		this.legalUnitsFieldCB.setText(dm.getLegalFee3B());
		this.legalFeeFieldC.setText(dm.getLegalFee3C());
		this.legalUnitsFieldDA.setText(dm.getLegalFee4A());
		this.legalUnitsFieldDB.setText(dm.getLegalFee4B());
		this.legalFeeFieldD.setText(dm.getLegalFee4C());
		
		this.inspectionUnitsFieldAA.setText(dm.getInspectionFee1A());
		this.inspectionUnitsFieldAB.setText(dm.getInspectionFee1B());
		this.inspectionFeeFieldA.setText(dm.getInspectionFee1C());
		this.inspectionUnitsFieldBA.setText(dm.getInspectionFee2A());
		this.inspectionUnitsFieldBB.setText(dm.getInspectionFee2B());
		this.inspectionFeeFieldB.setText(dm.getInspectionFee2C());
		this.inspectionUnitsFieldCA.setText(dm.getInspectionFee3A());
		this.inspectionUnitsFieldCB.setText(dm.getInspectionFee3B());
		this.inspectionFeeFieldC.setText(dm.getInspectionFee3C());
		this.inspectionUnitsFieldDA.setText(dm.getInspectionFee4A());
		this.inspectionUnitsFieldDB.setText(dm.getInspectionFee4B());
		this.inspectionFeeFieldD.setText(dm.getInspectionFee4C());
	}

	@Override
	public void focusGained(FocusEvent e) {
		
		
	}

	@Override
	public void focusLost(FocusEvent e) {
		dm.setAppraisalFee1A(FieldParser.parseInteger(this.appraisalUnitsFieldAA.getText()));
		dm.setAppraisalFee1B(FieldParser.parseInteger(this.appraisalUnitsFieldAB.getText()));
		dm.setAppraisalFee1C(FieldParser.parseInteger(this.appraisalFeeFieldA.getText()));
		dm.setAppraisalFee2A(FieldParser.parseInteger(this.appraisalUnitsFieldBA.getText()));
		dm.setAppraisalFee2B(FieldParser.parseInteger(this.appraisalUnitsFieldBB.getText()));
		dm.setAppraisalFee2C(FieldParser.parseInteger(this.appraisalFeeFieldB.getText()));
		dm.setAppraisalFee3A(FieldParser.parseInteger(this.appraisalUnitsFieldCA.getText()));
		dm.setAppraisalFee3B(FieldParser.parseInteger(this.appraisalUnitsFieldCB.getText()));
		dm.setAppraisalFee3C(FieldParser.parseInteger(this.appraisalFeeFieldC.getText()));
		dm.setAppraisalFee4A(FieldParser.parseInteger(this.appraisalUnitsFieldDA.getText()));
		dm.setAppraisalFee4B(FieldParser.parseInteger(this.appraisalUnitsFieldDB.getText()));
		dm.setAppraisalFee4C(FieldParser.parseInteger(this.appraisalFeeFieldD.getText()));
		
		dm.setLegalFee1A(FieldParser.parseInteger(this.legalUnitsFieldAA.getText()));
		dm.setLegalFee1B(FieldParser.parseInteger(this.legalUnitsFieldAB.getText()));
		dm.setLegalFee1C(FieldParser.parseInteger(this.legalFeeFieldA.getText()));
		dm.setLegalFee2A(FieldParser.parseInteger(this.legalUnitsFieldBA.getText()));
		dm.setLegalFee2B(FieldParser.parseInteger(this.legalUnitsFieldBB.getText()));
		dm.setLegalFee2C(FieldParser.parseInteger(this.legalFeeFieldB.getText()));
		dm.setLegalFee3A(FieldParser.parseInteger(this.legalUnitsFieldCA.getText()));
		dm.setLegalFee3B(FieldParser.parseInteger(this.legalUnitsFieldCB.getText()));
		dm.setLegalFee3C(FieldParser.parseInteger(this.legalFeeFieldC.getText()));
		dm.setLegalFee4A(FieldParser.parseInteger(this.legalUnitsFieldDA.getText()));
		dm.setLegalFee4B(FieldParser.parseInteger(this.legalUnitsFieldDB.getText()));
		dm.setLegalFee4C(FieldParser.parseInteger(this.legalFeeFieldD.getText()));
		
		dm.setInspectionFee1A(FieldParser.parseInteger(this.inspectionUnitsFieldAA.getText()));
		dm.setInspectionFee1B(FieldParser.parseInteger(this.inspectionUnitsFieldAB.getText()));
		dm.setInspectionFee1C(FieldParser.parseInteger(this.inspectionFeeFieldA.getText()));
		dm.setInspectionFee2A(FieldParser.parseInteger(this.inspectionUnitsFieldBA.getText()));
		dm.setInspectionFee2B(FieldParser.parseInteger(this.inspectionUnitsFieldBB.getText()));
		dm.setInspectionFee2C(FieldParser.parseInteger(this.inspectionFeeFieldB.getText()));
		dm.setInspectionFee3A(FieldParser.parseInteger(this.inspectionUnitsFieldCA.getText()));
		dm.setInspectionFee3B(FieldParser.parseInteger(this.inspectionUnitsFieldCB.getText()));
		dm.setInspectionFee3C(FieldParser.parseInteger(this.inspectionFeeFieldC.getText()));
		dm.setInspectionFee4A(FieldParser.parseInteger(this.inspectionUnitsFieldDA.getText()));
		dm.setInspectionFee4B(FieldParser.parseInteger(this.inspectionUnitsFieldDB.getText()));
		dm.setInspectionFee4C(FieldParser.parseInteger(this.inspectionFeeFieldD.getText()));
		
		dm.updateInterface();
	}
}
